package com.company.AtomicOption;

/**
 * 作者  Administrator
 * 时间  2017/6/12 18:08
 * 文件  ThreadPoolsDemo
 * 描述
 */
public class VolatileTest {
	public volatile int inc = 0;

	public void increase() {
		inc++;
	}

	public static void main(String[] args) {
		final VolatileTest test = new VolatileTest();
		for(int i=0;i<10;i++){
			new Thread(){
				public void run() {
					for(int j=0;j<1000;j++)
						test.increase();
				}
			}.start();
		}

		while(Thread.activeCount()>1)  //保证前面的线程都执行完
			Thread.yield();
		System.out.println(test.inc);
	}
}
